import java.util.Iterator;
import java.util.List;
import java.util.Vector;

class Sorterator implements Iterable<Integer> {
	java.util.Iterator<Integer> it1;
	java.util.Iterator<Integer> it2;
	int val1;
	int val2;
	boolean it1done = false;
	boolean it2done = false;

	public Sorterator(List<Integer> list1, List<Integer> list2) {
		it1 = list1.iterator();
		it2 = list2.iterator();

		it1done = !it1.hasNext();
		it2done = !it2.hasNext();

		if (it1.hasNext()) {
			val1 = it1.next();
		}

		if (it2.hasNext()) {
			val2 = it2.next();
		}
		

	}

	public boolean hasNext() {
		if (!it1done || !it2done) {
			return true;
		}
		return false;
	}

	public int next() {
		int result = val1;

		if (it2done || !it1done && val1 < val2) {
			result = val1;
			if (it1.hasNext()) {
				val1 = it1.next();
			} else {
				it1done = true;
			}

		} else {
			result = val2;
			if (it2.hasNext()) {
				val2 = it2.next();
			} else {
				it2done = true;
			}
		}		
		return result;
	}

	public static void main(String[] args) {
		List<Integer> l1 = new Vector<Integer>();
		l1.add(1);
		l1.add(3);
		l1.add(5);
		l1.add(7);
		l1.add(9);
		l1.add(9);
		List<Integer> l2 = new Vector<Integer>();
		l2.add(2);
		l2.add(4);
		l2.add(5);
		l2.add(6);
		Sorterator s1 = new Sorterator(l2, l1);

		while (s1.hasNext()) {
			System.out.println(s1.next());
		}
	}

	@Override
	public Iterator<Integer> iterator() {
		while (this.hasNext()) {
			
			
		}
		return null;
	}
}

//
// [1, 2, 5, 7, 9, 9 ]
// [3, 4, 7, 8]
//
// -> [1, 2, 3, 4, 5, 7, 7, 8]
//
//
// [1]
// [2]

